package kr.moiba.commonCd.dao.impl;

import java.util.List;
import java.util.Map;

import kr.moiba.commonCd.dao.CommonCdDao;
import kr.moiba.commonCd.domain.CommonCd;

import org.apache.ibatis.session.RowBounds;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Repository;

/**
 * @author Lee Youngho
 *
 */

@Repository
public class CommonCdDaoImpl extends SqlSessionDaoSupport  implements CommonCdDao {

	public CommonCdDaoImpl() {
		// TODO Auto-generated constructor stub
	}

	//헤더
	@Override
	public List<CommonCd> SelectListHeader(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer page = (Integer)condition.get("page");
		Integer maxnum = (Integer)condition.get("maxnum");
		
		List<CommonCd> result = null;
		if(page != null && maxnum != null){
			RowBounds rb = new RowBounds(page, maxnum);
			result = getSqlSession().selectList("CommonCd.selectList.header", condition, rb);
		}else{
			result = getSqlSession().selectList("CommonCd.selectList.header", condition);
		}
		
		return result;
	}
	
	@Override
	public Integer SelectListTotalCntHeader(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer result = getSqlSession().selectOne("CommonCd.selectListTotalCnt.header", condition);
		return result;
	}

	@Override
	public CommonCd selectHeader(Integer idx) throws Exception {
		// TODO Auto-generated method stub
		CommonCd result = (CommonCd)(getSqlSession().selectOne("CommonCd.select.header", idx)); 
		return result;
	}

	@Override
	public CommonCd insertHeader(CommonCd commonCd) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("CommonCd.insert.header", commonCd);
		return commonCd;
	}

	@Override
	public CommonCd updateHeader(CommonCd commonCd) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("CommonCd.update.header", commonCd);
		return commonCd;
	}
	
	@Override
	public int deleteHeader(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("CommonCd.delete.header", condition);
		return result;
	}
	
	//데이터
	@Override
	public List<CommonCd> SelectListData(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer page = (Integer)condition.get("page");
		Integer maxnum = (Integer)condition.get("maxnum");
		
		List<CommonCd> result = null;
		if(page != null && maxnum != null){
			RowBounds rb = new RowBounds(page, maxnum);
			result = getSqlSession().selectList("CommonCd.selectList.data", condition, rb);
		}else{
			result = getSqlSession().selectList("CommonCd.selectList.data", condition);
		}
		
		return result;
	}
	
	@Override
	public Integer SelectListTotalCntData(Map<String, Object> condition)
			throws Exception {
		// TODO Auto-generated method stub
		Integer result = getSqlSession().selectOne("CommonCd.selectListTotalCnt.data", condition);
		return result;
	}

	@Override
	public CommonCd selectData(Integer idx) throws Exception {
		// TODO Auto-generated method stub
		CommonCd result = (CommonCd)(getSqlSession().selectOne("CommonCd.select.data", idx)); 
		return result;
	}

	@Override
	public CommonCd insertData(CommonCd commonCd) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().insert("CommonCd.insert.data", commonCd);
		return commonCd;
	}

	@Override
	public CommonCd updateData(CommonCd commonCd) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("CommonCd.update.data", commonCd);
		return commonCd;
	}

	@Override
	public int deleteData(Map<String, Object> condition) throws Exception {
		// TODO Auto-generated method stub
		int result = getSqlSession().update("CommonCd.delete.data", condition);
		return result;
	}
}
